perm filename CATCH.PAL[SYS,HE] blob sn#125869 filedate 1975-02-07 generic text, type C, neo UTF8
COMMENT āŠ—   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002		Bo's special trapcatcher
C00004 ENDMK
CāŠ—;
;	Bo's special trapcatcher
;
;	This routine sets all unused (zero) trap vectors so that
;	they get you to the location BADTRP.  Call with this at
;	program startup:
;
;	JSR R5,TRPNIT		;Set up vectors from location 4 to the
;	  TRPEND		;first location you DON'T want trapped.
;
;	If your program winds up at BADTRP, the stack contains this:
;
;	(SP)	4 plus the location of the trap vector.
;	2(SP)	Garbage.
;	4(SP)	The PC and
;	6(SP)	PS stored by the trap.

TRPNIT:	.=%IOTV			;The trapcatcher uses the IOT instruction
	BADTRP			;to trap the traps.
	340
	.=TRPNIT

	MOV R0,-(SP)
	MOV #4,R0		;Start at loc 4.
TRPNI1:	CMP R0,(R5)		;Are we past the traps?
	BHIS TRPNI3
	TST (R0)+		;No.  Is this one in use?
	BEQ TRPNI2
	TST (R0)+		;It is.  Bypass it.
	BR TRPNI1
TRPNI2:	MOV R0,-2(R0)		;Not in use.  Set trap PC to next loc,
	MOV (PC)+,(R0)+		;which is an IOT instruction.
	  IOT
	BR TRPNI1
TRPNI3:	TST (R5)+		;Done.  Skip past the argument
	MOV (SP)+,R0		;and return.
	RTS R5